from typing import List, Optional
from pydantic import BaseModel

class Option(BaseModel):
    """选项模型"""
    key: str  # 选项键值 (A, B, C, D)
    content: str  # 选项内容

class QuestionBase(BaseModel):
    subject: str  # k1: 科目一, k4: 科目四
    model: str  # C1: 轿车, A2: 货车, D: 摩托车, A1: 公交车
    question_type: str  # theory: 理论考试, special: 专项训练
    content: str  # 题目内容
    options: List[str]  # 选项列表
    answer: str  # 正确答案
    explanation: Optional[str] = None  # 答案解释
    image_url: Optional[str] = None  # 题目图片URL

class QuestionCreate(QuestionBase):
    pass

class QuestionUpdate(QuestionBase):
    pass

class Question(QuestionBase):
    id: int

    class Config:
        from_attributes = True  # Changed from orm_mode = True

class ExamRequest(BaseModel):
    """考试请求模型"""
    subject: str  # k1: 科目一, k4: 科目四
    model: str  # C1: 轿车, A2: 货车, D: 摩托车, A1: 公交车
    count: int = 100  # 题目数量，默认100题

class QuestionResponse(Question):
    pass

class QuestionAnswer(BaseModel):
    question_id: int
    user_answer: str

class QuestionResult(BaseModel):
    question_id: int
    is_correct: bool
    correct_answer: str
    explanation: Optional[str] = None 